import {
  checkLogin
} from './auth.js'
new Vue({
  el: '#app',
  data: {
    IS_LOGIN: null,
    dataList: [],
    dialogFormVisible: false,
    pagination: {
      pageSizes: [5, 10, 20, 50, 100],
      queryString: '',
      currentPage: 1,
      pageSize: 5,
      total: 0
    },
    formData: {
      order: {

      },
      user: {

      }
    }
  },
  async created() {
    this.IS_LOGIN = await checkLogin()
    if (this.IS_LOGIN == null) {
      location.href = '/'
    }
    await this.getOrderList()
  },
  mounted() {

  },
  methods: {
    async getOrderList() {
      const res = await request.get('/order/getOrderList', {
        params: {
          queryString: this.pagination.queryString,
          currentPage: this.pagination.currentPage,
          pageSize: this.pagination.pageSize
        }
      })
      this.dataList = res.data.list
      this.pagination.total = res.data.pageTotal
    },
    handleQuery(item) {
      this.formData.order = item
      this.dialogFormVisible = true
      this.getUserInfo()
    },
    async getUserInfo() {
      const res = await request.get('/order/getUserByOrder', {
        params: {
          oid: this.formData.order.oid
        }
      })
      this.formData.user = res.data
    },
    async handleDelete(item) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await request.delete('/order/deleteOrderById', {
          params: {
            oid: item.oid
          }
        })
        this.getOrderList()
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleSizeChange(size) {
      this.pagination.pageSize = size
      this.getOrderList()
    },
    handleCurrentChange(currentPage) {
      this.pagination.currentPage = currentPage
      this.getOrderList()
    }
  }
})